package dao

import (
	"context"
	"wk/model"
)

type productDao struct {
	
}

func (p productDao) Add(ctx context.Context,product *model.Product) error {

	strSql := "INSERT INTO product(p_no,price,stock,color) VALUES(?,?,?,?)"
	result, err := masterDB.ExecContext(ctx, strSql, product.PNo,product.Price,product.Stock,product.Color)
	if err != nil {
		return err
	}

	id, err := result.LastInsertId()
	if err != nil {
		return err
	}

	product.ID = int(id)

	return nil

}
